package site.sorghum.ddl.field;

import java.sql.JDBCType;

public class PostgreSQLTypeConvert extends BasicTypeConverter {
    public static final TypeConverter INSTANCE = new PostgreSQLTypeConvert();

    @Override
    public String convertToDatabaseType(JDBCType jdbcType) {
        if (jdbcType == null) {
            throw new IllegalArgumentException("JDBC type cannot be null");
        }

        switch (jdbcType) {
            case BIGINT:
                return "BIGINT";
            case BOOLEAN:
            case BIT:
            case TINYINT:
            case SMALLINT:
            case INTEGER:
            case REAL:
            case NUMERIC:
                return "NUMERIC";
            case LONGVARCHAR:
                return "TEXT";
            case LONGVARBINARY:
                return "BYTEA";
            case TIME_WITH_TIMEZONE:
                return "TIME WITH TIME ZONE";
            case TIMESTAMP_WITH_TIMEZONE:
                return "TIMESTAMP WITH TIME ZONE";
            case FLOAT:
                return "REAL";
            case DOUBLE:
                return "DOUBLE PRECISION";
            case DECIMAL:
                return "DECIMAL";
            default:
                return super.convertToDatabaseType(jdbcType);
        }
    }
}
